# -*- coding:utf-8 -*-

'''
# 列表复制
import copy
lst0 = [1,[2,3,4],5]
lst5 = copy.deepcopy(lst0)
lst5[1][1] = 20
lst5 == lst0

'''

# 计算杨辉三角前６行
"""
# 方法1: 下一行依赖上一行所有元素,是上一行所有元素的两两相加的和,再在两头各加1.
triangle = [[1],[1,1]]
for i in range(2,6):
    cur = [1]
    pre = triangle[i-1]
    for j in range(len(pre)-1):
        cur.append(pre[j]+pre[j+1])
    cur.append(1)
    triangle.append(cur)
print(triangle)

# 方法2:计算杨辉三角前6行
trigh = []
n = 6
for i in range(n):
    row = [1]
    trigh.append(row)
    if i == 0:
        continue
    for j in range(i-1):
        row.append(trigh[i-1][j]+trigh[i-1][j+1])
    row.append(1)
print(trigh)

# 方法3: 计算杨辉三角前6行
n = 6
old = []
new = [1]
length = 0
print(new)
for i in range(1,n):
    old = new.copy()
    old.append(0) # 尾部加０，相当于２端加０
    new.clear()
    offset = 0
    while offset <= i:
        new.append(old[offset-1]+old[offset])
        offset += 1
    print(new)

# 方法4: 计算杨辉三角前6行
n = 6
old = []
new = [1]
length = 0
print(new)
for i in range(1,n):
    old = new.copy()
    old.append(0)  # 尾部加0
    new.clear()
    for j in range(i+1):
        new.append(old[j-1]+old[j])
    print(new)
"""


# 如何比较这两段代码的效率?
import math
n = 100
num = []
count = 0
for x in range(2,n):
    for i in num:
        count += 1
        if x % i == 0:
            break
    else:
        # print(x)
        num.append(x)
print(num)
print(count)

'''
number = []
flag = False
for x in range(2,100000):
    for i in number:
        if x % i == 0:
            flag = True
            break
        if i >= math.ceil(math.sqrt(x)):
            flag = False
            break
    if not flag:
        print(x)
        number.append(x)
'''


